function OnSize() {
	var bSize = false;
	//获取原始窗口的高度
	var originalHeight = document.documentElement.clientHeight || document.body.clientHeight;
	window.onresize = function() {
		//软键盘弹起与隐藏  都会引起窗口的高度发生变化
		var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
		if(!bSize){
			OnSlow(resizeHeight,originalHeight)
//			plus.webview.currentWebview().setStyle({
//				height: originalHeight
//			});
			bSize = true;
		}

	}
}

function OnSlow(begin,end ){
	if(begin >= end){
		return;	
	}
	
	begin += 2
	if(begin > end){
		begin = end;
	}
	plus.webview.currentWebview().setStyle({
		height: begin
	});
	
	setTimeout(function(){OnSlow(begin,end);},10);
}


function OnDrawBg() {
	// --------------demo start------------------
	new DrawBg({
		imgData: [
			'../../images/bg/1.png',
			'../../images/bg/2.png',
			'../../images/bg/3.png'
		],
		currentIdx: 0, //当前所在页面
		check_time: 6, //页面切换时间
		animate_time: 10, //动画运行时间
		animate: "", //当前起始页面的动画效果，参数有["left","right","top","bottom","scale_small"，"scale_big"]
		modal_color: "#000", //蒙层颜色 规则为 rgb(0,0,0) || #000; 默认为000
		opacity: 0.4, //透明度 0-1 默认为0.2
	});
	//--------------end------------------
}

var input_phone = document.getElementById("phone");
var input_verify = document.getElementById("verify");
var is_btn = true;

var Blur = function() {
	input_phone.blur();
	input_verify.blur();
}

mui.init({
	beforeback: function(){
		plus.webview.getWebviewById('login.html').evalJS("OnSetAuto(true);OnPlay(true);");
	}
});
	
mui.plusReady(function() {
	OnDrawBg();
	OnSize();

	plus.nativeUI.closeWaiting(); //关闭等待框
	mui.currentWebview.show(); //显示当前页面

	//获取验证码
	mui(".verify").on("tap", "button", function() {
		Blur();
		if(is_btn == false){
			return;
		} 
		text_phone = input_phone.value
		if(text_phone.length == 0) {
			mui.toast("请正确输入手机号")
			return;
		}
		btn = this;
		require(["bind"], function(bind) {
			bind.OnVerify(text_phone,text_phone,false, function(data) {
				mui.toast("获取验证码成功。");
				//开始倒计时60秒
				StartTimeOut();
			});
		});
	})

	//提交
	var btn_bind = document.getElementById("bind");
	btn_bind.addEventListener("tap", function() {
		Blur();
		text_phone = input_phone.value
		text_verify = input_verify.value

		if(text_phone.length == 0 || text_verify.length == 0) {
			mui.toast("请正确填写")
			return;
		}

		require(["bind","request"], function(bind,request) {
			bind.OnGetUserByPhone(text_phone, text_verify,text_phone, function(data) {
				mui.toast("请设置密码")
				OnOpenWindow("./forget.html", "forget.html",{url:request.Main_Host + data.url,id_card:data.id_card})
			});
		});

	});

	//跳过此步
	var btn_jump = document.getElementById("jump");
	btn_jump.addEventListener("tap", function() {
		OnOpenWindow("./getpwdby_photo.html", "getpwdby_photo.html")
	});
	

	
});

function StartTimeOut() {
	is_btn = false;
	var click = 60;
	var span = document.getElementById("click");
	span.innerHTML = `60 <span>s</span>`
	var call = function() {
		click--;
		if(click > 0) {
			span.innerHTML = click + ` <span >S</span>`
			setTimeout(call, 1000);
		} else {
			is_btn = true;
			span.innerHTML = ""
		}
	}
	setTimeout(call, 1000);
}